package com.untrance.shop.core.builder.query;

import javax.persistence.Query;

import com.untrance.shop.common.filters.model.PaginableFilter;

/**
 * @author eugene zadyra
 */
public abstract class AbstractPaginableQueryBuilder<F extends PaginableFilter> extends AbstractQueryBuilder<F> {

	@Override
	public Query buildQuery(){
		Query query = super.buildQuery();
		if(filter.getItemsPerPage()!=null){
			query.setMaxResults(filter.getItemsPerPage());
		}
		if(filter.getFirstResult()!=null){
			query.setFirstResult(filter.getFirstResult());
		}
		return query;
	}
	
	protected abstract String getEntityName();

	protected abstract String getOrderField();

}
